extends RefCounted


class_name EventProcessor


@export var unique: EffectValue = null
@export var effects: Array[EffectValue] = []


func on_event(effect: EffectValue, character: CharacterComponent, e: CharacterEvent) -> void:
    if effect and effect.value > 0:
        effect.behavior.do_event(character, effect, e)

func do_event(character: CharacterComponent, e: CharacterEvent) -> bool:
    on_event(unique, character, e)
    for effect in effects:
        on_event(effect, character, e)
    return e.is_canceled

func clone() -> EventProcessor:
    var other: EventProcessor = EventProcessor.new()
    if unique:
        other.unique = unique.duplicate()
    for e in effects:
        other.effects.append(e.duplicate())
    return other
